'use strict';{_Ik=_wj(function*(e,d){try{let h=yield W(e.props,e.args,e.scriptId,d,e.targetTabs,e.trigInstId);return h instanceof z?h:{result:h}}catch(h){return{error:`ACtl.${e.props[0]}: ${h.message||h}.`}}});let z=function(e,d){if(!new.target)return new z(e,d);e=63>_Ok?e+"":(e+"").replace("__IMPORT__","import");this.add({funcCode:e,args:d})},I=function(e,d){let h=_oi(e).toUpperCase();for(let k of _Ws(d))if(_oi(_er(k).name).toUpperCase()==h)return k;throw`${({tse:"Tab selection",script:"Script"})[d]} "${e}" does not exist`;
},J=function(e){return Object.defineProperty(e,Symbol.iterator,{value:function*(){for(let d in this)this.hasOwnProperty(d)&&(yield[d,this[d]])}})},C=function(e,d,h,k,t,n){function p(r,g){let a=new Uint8Array(r.length);for(let b=0;b<r.length;++b)a[b]=r.charCodeAt(b);return new Blob([a],{type:g})}function v(){return new Promise((r,g)=>{let a=new Image;a.onload=()=>r(a);a.onerror=()=>g(`"${t}" is not a valid image file.`);a.src=URL.createObjectURL(x())})}let x=()=>new File([p(atob(d),h)],t,{type:h,lastModified:n});
switch(e){case "base64":return d;case "binary":return atob(d);case "blob":return p(atob(d),h);case "file":return x();case "objectUrl":return URL.createObjectURL(x());case "dataUri":return`data:${h}${k?";charset="+k:""};base64,`+d;case "image":return v();case "canvas":return v().then(r=>{{let g=document.createElement("canvas");g.width=r.width;g.height=r.height;g.getContext("2d").drawImage(r,0,0,g.width,g.height);r=g}return r})}return(new Promise(r=>{let g=new FileReader;g.onload=()=>r(g.result);g.readAsText(p(atob(d),
h),k)})).then(r=>{switch(e){case "json":try{return JSON.parse(r)}catch(a){throw`Invalid JSON in file "${t}": ${a.message}`;}case "xmlDoc":case "htmlDoc":return(new DOMParser).parseFromString(r,"text/"+("xmlDoc"==e?"xml":"html"));case "html":var g=document.createElement("template");g.innerHTML=r;return g.content;case "css":return g=document.createElement("style"),g.textContent=r,document.implementation.createHTMLDocument().head.appendChild(g);case "module":return r=new Blob([r],{type:"text/javascript"}),
r=URL.createObjectURL(r),__IMPORT__(r).catch(a=>{a.message+=` in file "${t}"`;throw a;});default:return r}})},K=function(e,d,h,k=.9){function t(a){Array.from(a.querySelectorAll("br")).forEach(b=>b.parentNode.replaceChild(new Text("\r\n"),b));return a.textContent}function n(a){return b=>{let c=new FileReader;c.onload=()=>b(btoa(c.result));c.readAsBinaryString(a)}}function p(a){a=new Uint8Array(a);let b="";for(let c=0;c<a.length;++c)b+=String.fromCharCode(a[c]);return b}function v(a){return a.substr(a.indexOf(",")+
1||a.length)}function x(a){a=a.toLowerCase();return"image/"+({ico:"x-icon",cur:"x-icon",jpg:"jpeg"}[a]||a)}function r(a){let b=document.createElement("canvas");b.width=a.width;b.height=a.height;b.getContext("2d").drawImage(a,0,0,b.width,b.height);return b}let g=window[e];delete window[e];if("object"==typeof g){if(g instanceof Blob)return a=>n(g)(b=>a(["bin",b]));if(g instanceof ArrayBuffer)return["bin",btoa(p(g))];if(!h||0>h.indexOf("/"))h=x(h||d);if(g instanceof HTMLImageElement||g instanceof SVGImageElement)g=
r(g);if(g instanceof HTMLCanvasElement)return["image",v(g.toDataURL(h,k))];if(window.OffscreenCanvas&&g instanceof OffscreenCanvas)return a=>g.convertToBlob({type:h,quality:k}).then(b=>n(b)(c=>a(["image",c])));if(g instanceof Element){d="";if(e=document.contains(g))d=(d=document.querySelector("base[href]"))?d.href:location.href,d=`<base href="${d}">`;return["html",g.outerHTML,{srcUrl:g.sourceURL||(e?location.href:""),text:g.innerText,ctxHtml:d}]}return g instanceof DocumentFragment?["html",[].map.call(g.childNodes,
a=>a.outerHTML||a.textContent).join(""),{srcUrl:g.sourceURL,text:t(g)}]:["json",JSON.stringify(g)]}g+="";try{return["bin",btoa(g)]}catch(a){return["text",g]}},L=(e,d)=>h=>{_So(_r,e,k=>h(`File system error: ${k.trim()} "${d}"`))};const X={leftmostTab:"firstTab",rightmostTab:"lastTab",selectedTabs:"highlighted",mruTabs:"currWinTabsMruOrder",mruTabsAllWins:"allTabsMruOrder"};let Q=e=>e.filter(d=>!_Ns(_7j(_os[d]))),M=e=>{throw"Invalid tab specifier: "+e;},A=()=>{throw"Invalid argument types";},R=()=>
{throw"A tab must be specified when running in the background";},D=_wj(function*(e,d=!0,h,k,t=!0){t||(_Fo=!0);let n;if(null==e||""===e)n=[];else if(+e&&!0!==e&&Number.isInteger(+e))n=[+e];else if("string"==typeof e){var p=e.trim();let v;"#"==p[0]&&(v=X[p.slice(1)]||p.slice(1),"targetTabs"==v?n=h:null==_er(v,"tse").value&&(v=null));n||(v||(v=I(p,"tse")),yield _Co(),n=yield _fr(k,_4j,v))}else if(_Mg(e)){n=[];for(let v of e)p=yield D(v,t,h,k),p.length&&n.push(p)}else if("object"==typeof e){yield _Co();
n=[];for(let [v,x]of e)switch(v){case "not":let r=yield D(x,!0,h,k);n.push(Object.keys(_os).map(g=>+g).filter(g=>-1==r.indexOf(g)));break;case "intersect":_Mg(x)||M("'intersect' must be an array");t=[];for(p of x)t.push(yield D(p,!0,h,k));n.push(t.length?_0p(...t):[]);break;case "sameWinAs":t=yield D(x,!0,h,k);n.push(_3y(..._yg(t).map(g=>_sk[g].tabs.map(a=>a.id))));break;default:n.push(Object.keys(_os).filter(g=>{g=_Qy(_os[g],v);var a=x;void 0===g&&M(`Unknown filter '${v}'`);g=a instanceof RegExp?
a.test(g):a&&"string"==typeof a.RE&&3>Object.keys(a).length?RegExp(a.RE,a.F).test(g):g==a;return g}).map(g=>+g))}n.length&&(n=[_0p(...n)])}if(n)return d?_Nd(n):n;M(e)}),Y=_wj(function*(e,d=!0){d&&(yield t=>_vi(t));d=_os[e];if(!d)return null;e={window:{}};const h="active audible favIconUrl height id incognito index muted openerTabId pinned selected status title url width".split(" ");for(var k of h)e[k]=_Qy(d,k);e.url+="";e.status={discarded:"unloaded",complete:"loaded"}[e.status]||e.status;k=_Qy(d,
"window");d="alwaysOnTop focused height left state top type width".split(" ");for(let t of d)e.window[t]=k[t];return e}),O=_wj(function*(e,d,h){d=yield N(d,e);if(_0j(d)){e=h.in("text","json","module","html","htmlDoc","xmlDoc","css");e=yield _i(d,e?"charEnc":"");if(e.error)throw yield L(e.error,d);return[h,btoa(e.content),e.mime,e.charEnc,d,e.modTime]}{let [t,n]=yield _Ya(_n(d,"binary"));if(200!=n.status)throw`HTTP error '${_1k(n.status,n)}' ${d}`;var k=n.getResponseHeader("content-type")||"";e=(k.match(/^[^;]+/)||
["application/octet-stream"])[0];k=(k.match(/charset="?([^";]+)/)||[,""])[1].toUpperCase();let p=+new Date(n.getResponseHeader("last-modified"));return[h,btoa(t),e,k,d,p]}}),N=_wj(function*(e,d,h=!1){e=(e+"").trim();e.startsWith("data:")||(e=yield _9y(e));if(!_Zk(e)){d=yield _9y(_Kg(_er(d),"value","srcFile"));if(h?!_0j(d):!d)throw`'${e}' is not an absolute file path or URL`;e=(new URL(e,d)).href}_0j(e)&&(e=new URL(e),e=decodeURI(e.href.slice(e.host?5:8)).replace(/\//g,"\\").replace(/(?!^)\\{2,}/g,
"\\"));return e}),P=_wj(function*(e,d){return e=yield N(e,d,!0)}),F=function(e,d,h){return _bf(e,{funcCode:h+"",args:_3y(d)})},G=function(e,d,h){return _bf(e,{scrtCtxVar:d,value:h})},W=_wj(function*(e,d,h,k,t,n){function p(a,b=!0){return D(a,b,t,n,!1)}function v(a){return a.substr(a.indexOf(",")+1||a.length)}function x(a){a=a.toLowerCase();return"image/"+({ico:"x-icon",cur:"x-icon",jpg:"jpeg"}[a]||a)}function r(a){try{new URL(a)}catch(b){throw`'${a}' is not a valid URL`;}}let g=e[0];switch(g){case "sleep":{let [a]=
d;yield _Pi(a);return}case "pubVar":d.pubVar=!0;case "var":{let [a,b]=d,c=d.pubVar?"":h;if(0==d.length)return z(J,[(yield _7d(c))||{}]);if(1==d.length&&"object"==typeof a){let f={};for(let [q,m]of a)f[_Es(c,q).join(".")]=_o(m);let l=yield _ks(f);if(l)throw l;return}if("string"==typeof a){if(1==d.length)return yield _7d(c,a);let f=yield _Ti(c,a,b);if(f)throw f;return}A()}case "getScript":{let [a]=d;return yield _Je(I(a,"script"))}case "include":{let [a,b="",c=!1]=d;2==d.length&&"string"!=typeof b&&
([c,b]=[b,""]);const f="include "+a;let l=c||!(yield G(k.id,f));if(l){let q=yield O(h,a,"text"),m=yield C(...q),u=!q[2].match(/css/)&&!a.match(/\.css$/i)&&!(b+"").match(/^css$/i)||(b+"").match(/^js$/i);if(k.id){let w=u?"executeScript":"insertCSS";yield B=>_Ky.tabs[w](k.id,{code:m,runAt:"document_start"},B)}else yield _bf(0,{insertCode:m,type:u?"js":"css"});yield G(k.id,f,!0)}return!!l}case "import":d[1]="module";case "getFile":{let [a,b="text"]=d,c=yield O(h,a,b);return z(C,c)}case "saveFile":{let [a,
b,c]=d;c=c||{};a=yield P(a,h);let f=a.match(/[^.\/\\]*$/)[0],[l,q]=yield F(k.id,[b,f,c.format,c.quality],K);q=l.in("bin","image")?atob(q):_uu(q,c.format,!c.append);let m=yield _ok(a,q,null,c.append);if(m)throw yield L(m,a);return a}case "saveURL":{let [a,b]=d;r(a);b=yield P(b,h);let [c,f]=yield _Ya(_n(a,"binary"));if("\\"==b.slice(-1)){if(a.startsWith("data:"))throw"A filename must be specified when saving a data URI";let q=_Kw(f);b+=q}let l=yield _ok(b,c);if(l)throw yield L(l,b);return b}case "getTabIds":{let [a,
b=!0]=d;return yield p(a,b)}case "getTabInfo":{let [a]=d;a||0!=k.id||R();a=a?yield p(a):[k.id];_Ro=yield _3i(_yg(a));let b={},c=0;for(let f of a){let l=yield Y(f,!c++);if(l||1==a.length)b[f]=l}return z(J,[b])}case "runInTab":{let [a,b,c]=d;2==d.length&&([b,c]=[c,b]);a=Q(yield p(a));if("string"==typeof c||1==d.length){let f=1==d.length?h:I(c,"script"),l=yield _Je(f);return yield _2g(f,a,a,l,void 0,n)}if(c&&c.FUNC)return yield _2g(h,a,a,c.FUNC,_3y(b),n);A()}case "runInFrames":{let [a,b,c,f]=d;3==d.length&&
([c,f]=[f,c]);a=Q(yield p(a));if(f&&f.FUNC&&"object"==typeof b)return[].concat(...yield _2g(h,a,a,f.FUNC,_3y(c),n,!1,b));A()}case "runInPageCtx":{let [a,b]=d;if(1==d.length||2==d.length&&!b.FUNC)[a,b]=[b,a];if(0==k.id)throw"this function cannot be used in background scripts";if("string"==typeof b){b=yield N(b,h);const c="runInPageCtx "+b;let f=a||!(yield G(k.id,c));if(f){let l=b;if(_0j(b)){let m=yield O(h,b,"objectUrl");l=z(C,m)}let q=yield F(k.id,l,m=>runInPageCtx(m.funcCode?FN(m.funcCode)(...m.args):
m));if(q.error)throw q.error;yield G(k.id,c,!0)}return!!f}if(b&&b.FUNC){let c=yield F(k.id,[b.FUNC,_3y(a)],(f,l)=>q=>{runInPageCtx("funcExecLstnr",()=>{window.addEventListener("message",u=>{if(u.source==window&&u.data.funcName&&u.data.args){try{var w={result:window[u.data.funcName](...u.data.args)}}catch(y){w={error:y.message||y}}delete window[u.data.funcName];let B=y=>window.postMessage({response:y,funcName:u.data.funcName},"*");w.result instanceof Promise?w.result.then(y=>B({result:y}),y=>B({error:y})):
B(w)}})})();let m="_"+(Math.random()+"").slice(2);window.addEventListener("message",function B(w){w.source==window&&w.data.funcName==m&&w.data.response&&(q(w.data.response),window.removeEventListener("message",B))});runInPageCtx({code:`var ${m} = ${f}`})();window.postMessage({funcName:m,args:l},"*")});if(c.error)throw c.error;return c.result}A()}case "openURL":{let [a,b]=d;a=_3y(a);for(let l of a)r(l);let c={url:a,winType:"normal",newTabs:!0},f=[];b&&(1==Object.keys(b).length&&(b.newWindow||b.leftOf||
b.rightOf)?b.leftOf?(c.tabPos="before",c.refTab=(yield p(b.leftOf))[0]):b.rightOf?(c.tabPos="after",c.refTab=(yield p(b.rightOf))[0]):(c.tabPos="newWin",c.incognito=!!(b.newWindow+"").match(/\bincognito\b/i),(b.newWindow+"").match(/\bpopup\b/i)&&(c.winType="popup")):f=yield p(b));return(yield l=>_a(f,l,c))[0]}case "closeTab":{let [a]=d;if(!a&&0==k.id)return[];a=a?yield p(a):[k.id];yield b=>_Zu(a,b);return a.length}case "setTabState":{let [a,b,c=_be,f=!0]=d;if(!a&&0==k.id)return 0;a=a?yield p(a):[k.id];
const l={active:"activateTabs",focused:"focusWin",selected:"highlightTabs",pinned:"pinTabs",muted:"muteTabs",minimized:"minimizeWins",maximised:"maximizeWins",maximized:"maximizeWins",restored:"restoreWins",fullscreen:"fullscreenWins",hidden:"hideWins",topmost:"topmostWins"};b=_oi(b).split(" ");for(let q of b){if(!l[q])throw`'${q}' is not a valid state`;yield m=>_vi(m);yield m=>_er(l[q],"action").value(a,m,{mode:c==_up?+c:+!!c,noAnim:!f})}return a.length}case "execAction":{let [a,b]=d,c=a;if(!(a instanceof
RegExp)){a=_oi(a);let m=a.slice(1),u=_er(m,"action");if("#"==a[0]&&u){b||0!=k.id||(b="#currentTab");b=b?yield p(b,!1):[k.id];let w=_Mg(u.value)?u.value:[{sequence:[{action:m}]}];return _Nd(yield _Ji(w,b))}}b&&(b=yield p(b,!1));let f=[],l=yield _qf("trigActList"),q=0;for(let [m,u]of l)if(!u.disabled&&(a instanceof RegExp?a.test(u.title):!_bo(a,_oi(u.title)))){let w=yield _Ji(_Sg[m],b);f.push(...w);++q}if(0==q)throw`No action found for "${c}"`;return _Nd(f)}case "favoriteTabs":{let [a,b="",c=[]]=d;
c=yield p(c);yield f=>_vi(f);yield f=>_ts(c,f,{listId:a,oper:_oi(b).toLowerCase()});return _7f[a]}case "runCommand":{let [a,b="",c=!1]=d;"boolean"==typeof b&&([c,b]=[b,""]);b||(b="<desktop>");b=yield P(b,h);let f=yield _Od(a,b,c);if(f.error)throw"System error: "+(yield _fw(_r,f.error)).trim();return f}case "getClipboard":{let [a,b="binary"]=d;a=_oi(a).toLowerCase();if("format"==a)return S[_8f.trueFmt];const c="text"==a,f=a.in("jpg","jpeg","png","webp");if(a&&!c&&!f)throw`'${a}' is not a valid format`;
let l=yield _Qr(c?_hj:null);if(f&&l.format!=_Ga)return"";switch(l.format){case _hj:case _ph:return l.content;case _O:return c?l.content.join("\n"):l.content;case _pe:return z(q,[_Fs(l.content),_Lo+""]);case _Ga:{let m=btoa(l.content),u="image/png";if(f){if("png"!=a&&(window._987654321qwerty_=yield C("canvas",m,u),[,m]=K("_987654321qwerty_",a),u=x(a)),!_Vy(b,"binary","blob","dataUri","objectUrl","base64","image"))throw`'${b}' is not a valid return type`;}else b="canvas";return z(C,[b,m,u])}}return"";
function q(m,u){u=FN(u)(m.fragment);u.sourceURL=m.sourceURL;Object.defineProperty(u,"innerHTML",{get(){return[].map.call(this.childNodes,w=>w.outerHTML||w.textContent).join("")}});return u}}case "setClipboard":{let [a]=d,[b,c,f={}]=yield F(k.id,[a,"png"],K),l="";switch(b){case "bin":c=atob(c);case "text":b=_hj;break;case "image":b=_Ga;break;case "json":c=JSON.parse(c);if(_Mg(c)){b=_O;c=c.map(q=>(q+"").replace(/\//g,"\\"));c=yield _9y(c);break}if("string"==typeof c.image){b=_Ga;c=c.image.startsWith("data:")?
v(c.image):btoa(c.image);break}else"string"==typeof c.html?(c=c.html,f.srcUrl=c.sourceURL,f.text=(new DOMParser).parseFromString(c,"text/html").body.innerText):A();case "html":b=_pe;_hw(f.text,_hj)();c=_hy(c,f.srcUrl,f.ctxHtml);l="addFmt";break;default:A()}return yield _hw(c,b,l)}case "captureTab":{let [a,b="dataUri"]=d;a||0!=k.id||R();if(!_Vy(b,"binary","blob","dataUri","objectUrl","base64","canvas","image"))throw`'${b}' is not a valid return type`;a=a?yield p(a):[k.id];let c={};for(let f of a){yield m=>
_vi(m);let l=_os[f];if(!l)continue;l.active||(yield m=>_pi([f],m,{peek:!1}));let q=yield m=>_Ky.tabs.captureVisibleTab(l.windowId,{format:"png"},m);_fy()?1==a.length&&(c[f]=null):("dataUri"!=b&&(q=z(C,[b,v(q),x("png")])),c[f]=q)}return z(J,[c])}case "on":{let [a,b,c]=d;b&&b.FUNC&&([b,c]=[c,b]);b=b?yield p(b):[0];if(c&&c.FUNC){c.refCount=0;for(let f of _oi(a).split(" ")){let l=Z(f),q=_Vy(l,_sd,_Yd,_vr,_vd);for(let m of q?[0]:b)++c.refCount,_ih(_li,l,{},m,{},k.id,h,[]).push(c),m&&aa()}return z(f=>window[f]("promise"),
[c.FUNC])}A()}case "off":{let [a,b]=d;1==d.length&&_Mg(a)&&([a,b]=[b,a]);(a&&"string"!=typeof a||b&&!_Mg(b))&&A();a&&(a=_oi(a).split(" "));let c=new _do,f=k.id;for(let [l,q]of _li){let m=T(l);if(!a||0<=a.indexOf(m))for(let [u,w]of q){let B=_Kg(w,f,h)||[];for(let y of B)(!b||0<=b.indexOf(y.FUNC))&&setTimeout(c.onReady(()=>{B.remove(y,!0);_hi(_li,l,u,f,h);1>--y.refCount&&_bf(f,{funcName:y.FUNC,event:{delete:!0}})()}))}}yield l=>c.setCallback(l);return}case "expand":{let [a,b,c]=d;"array"!=b&&"string"!=
b||null!=c||([b,c]=[c,b]);"string"!=typeof a&&A();let f=_Mu(a);_3t();let l=[];if(ba(a)){b=b?yield p(b):[k.id];for(let q of b)l.push(...yield _fr(n,_6s,f,_os[q]))}else l=yield _fr(n,_6s,f);return"array"==c?l:l.join("\v").replace(/\n?\v/g,"\n")}case "switchState":{let [a,b]=d;a=_oi(a);for(let [c,f]of _Ot.binSwtch)if(!_bo(a,f.name))return 1==d.length?_gy[c]:_es(c,b);return}case "getEnv":{let a=e.slice(1).concat(...d.map(b=>"string"==typeof b?b.split("."):A()));if(1==a.length&&"eventData"==a[0])return _7o(n).data;
return}case "natMsg":return}if(g)throw"This function does not exist";}),E={},ba=e=>{if(!(e in E)){let d=Object.keys(E);5<=d.length&&delete E[d[0]];E[e]=_6i(e)}return E[e]};const U={tabOpen:_vd,tabClose:_Lr,tabActivate:_uw,tabUnload:_j,tabLoadBegin:_vw,tabLoadEnd:_Qo,tabAudioBegin:_8j,tabAudioEnd:_ve,winOpen:_Yd,winClose:_vr,winFocus:_6h,clipboardChange:_sd,winUnfocus:_Gp,tabFocus:_5f,tabUnfocus:_vf,tabDeactivate:_bs,winMinimize:_fd,winUnminimize:_wh,tabUrlChange:_me};let Z=function(e){const d=U[e];
if(d)return d;throw`'${e}' is not a valid event name`;},T=function(e){for(let [d,h]of U)if(h==e)return d},aa=function(){H.alreadyAdded||_Ky.tabs.onRemoved.addListener(H)},H=function(e){let d=!1;for(let [h,k]of _li)for(let [t,n]of k)if(d=0<t,t==e)for(let [p,v]of n)for(let [x,r]of v)for(let g of r)setTimeout(()=>{r.remove(g,!0);_hi(_li,h,t,p,x);1>--g.refCount&&_bf(p,{funcName:g.FUNC,event:{delete:!0}})()});d||(_Ky.tabs.onRemoved.removeListener(H),H.alreadyAdded=!1)},V=function(e,d,h){let k=_li[e][d];
if(k)for(let [t,n]of k)for(let [p,v]of n)for(let x of v)_bf(t,{funcName:x.FUNC,event:h})(r=>{r||(v.remove(x,!0),_hi(_li,e,d,t,p))})};var _li={},_cf=_Et(function*(e,d){if(_li[e]){let h={type:T(e)},k;if(e.in(_6h,_Gp,_Yd,_fd,_wh)){let t=yield n=>_Ve(d,n);_fy();h.tabId=t.id;e!=_Yd&&(k=h.tabId)}else e!=_vr&&(e==_sd?h.clipFormat=S[_8f.trueFmt]:k=h.tabId=d);k&&V(e,k,h);V(e,0,h)}});const S={[_hj]:"text",[_ph]:"text",[_pe]:"html",[_O]:"files",[_Ga]:"image",0:"unknown"}};
